<template>
  <view>
    <view>
      <view style="display:flex;justify-content:center;width: 100%">
        <img style="width: 100px; height: 100px; margin-top: 40%; border-radius: 50%;" src="https://xyh.zjit.ac.cn/profile/upload/2024/12/06/logo02.png" alt="Logo" />
      </view>
      <u-button :customStyle="{'marginTop':'20%','width':'80%'}" plain type="primary" open-type="getPhoneNumber"
                @getphonenumber="getPhone">
        手机号快捷登录
      </u-button>
    </view>
    <view class="bottom">
      <view>
        <u-icon @click="checked=!checked" :name="checked?images.selected:images.un_selected" size="30"></u-icon>
      </view>
      <view class="hint">
        我已阅读并接受
        <text @click="navigateTo('/subPackageB/common/textview/index?title=用户协议&type=1')" class="link">《用户协议》</text>
        和
        <text @click="navigateTo('/subPackageB/common/textview/index?title=隐私政策&type=2')" class="link">《隐私政策》</text>
      </view>
    </view>
    <m-privacy title="服务协议" service-contract-name="用户服务协议" @agree="checked=true" ref="privacy" :auto="false"/>
  </view>
</template><script>
import config from "@/config"
import images from "@/utils/images"
import MPrivacy from "@/components/m-privacy/index.vue";
import {getWxUserPhone} from "@/api/login";export default {
  components: {MPrivacy},
  data() {
    return {
      js_code: null,
      checked: false,
      config,
      images,
      phone: '13782500860'
    }
  },
  mounted() {
    uni.login({
      onlyAuthorize: true,
      provider: 'weixin', //使用微信登录
      success: (res) => {
        this.js_code = res.code
      }
    });
  },  methods: {
    getPhone(e) {
      if (this.checked === false) {
        this.$refs.privacy.open()
        return
      }
      getWxUserPhone({
        encryptedData: e.detail.encryptedData,
        iv: e.detail.iv,
        code: this.js_code,
      }).then(re => {
        this.phone = re.data.phoneNumber
        this.$store.dispatch('PhoneLogin', this.phone).then((res) => {
          this.$store.dispatch('GetInfo')
          uni.switchTab({url: '/pages/tabbar/index'});
        });
      })    },
  }
};
</script><style lang="scss" scoped>
.bottom {
  margin-top: 5%;
  width: 100%;
  justify-content: center;
  display: flex;
  align-items: center;  .hint {
    padding: 20rpx 10rpx;
    font-size: 25rpx;
    color: $u-tips-color;    .link {
      color: $u-type-primary;
    }
  }
}
</style>